import { customerFieldList } from '@/api/customer'
const state = {
  fieldList: []
}

const mutations = {
  SET_FIELDLIST: (state, data) => {
    state.fieldList = data
  }
}

const actions = {
  customerFieldList({ commit }, data) {
    return new Promise((resolve, reject) => {
      customerFieldList().then(res => {
        const { data } = res
        data.forEach(element => {
          element.value1 = ''
          element.type = 1
          element.fieldCode = element.fieldCode.replace('_', '')
          try {
            // console.log(element.value)
            // console.log(JSON.parse(element.value))
            element.value = JSON.parse(element.value)
            if (element.value instanceof Array) {
              element.type = 2
            }
          } catch (error) {

          }
        })
        commit('SET_FIELDLIST', data)
        resolve(data)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

